package cn.sccl.dirms.topo.discovery.controller;

import cn.sccl.common.model.PageResult;
import cn.sccl.common.web.BaseController;
import cn.sccl.dirms.topo.discovery.model.DiscoverTaskSchedule;
import cn.sccl.dirms.topo.discovery.service.DiscoverTaskScheduleManager;
import com.fasterxml.jackson.annotation.JsonView;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
* 自动发现规则 的Controller
* Created by _minus on 2017-09-25.
*/
@RestController
@RequestMapping(value = "/nms/topo/discovery/discoverTaskSchedule")
public class DiscoverTaskScheduleController extends BaseController {

    @Autowired
    private DiscoverTaskScheduleManager discoverTaskScheduleManager;

    /**
    * 显示所有数据
    */
    @RequestMapping(value = "/all" , method = RequestMethod.GET)
    public List<DiscoverTaskSchedule> listAllDiscoverTaskSchedule(){
        return discoverTaskScheduleManager.listAll();
    }

    /**
    * 分页查询，分页参数放置在url路径中
    * @param pageIndex 页码
    * @param pageSize 分页大小
    * @param request
    * @return
    */
    @RequestMapping(value = "/page/{pageIndex}/{pageSize}" , method = RequestMethod.GET)
    public PageResult<DiscoverTaskSchedule> pageQueryDiscoverTaskSchedule(@PathVariable("pageIndex") long pageIndex , @PathVariable("pageSize") int pageSize , HttpServletRequest request){
        return discoverTaskScheduleManager.pageQueryByLike(pageIndex, pageSize, getQueryData(request));
    }

    /**
    * 分页查询，分页参数放置在request中
    * @param request
    * @return
    */
    @RequestMapping(value = "/page" , method = RequestMethod.GET )
    public PageResult<DiscoverTaskSchedule> pageQueryDiscoverTaskSchedule(HttpServletRequest request){
        return discoverTaskScheduleManager.pageQueryByLike(getPageIndex(request), getPageSize(request), getQueryData(request));
    }

    /**
    * 保存数据
    * @param discoverTaskSchedule
    * @return
    */
    @RequestMapping(value = "/" , method = RequestMethod.POST)
    public DiscoverTaskSchedule saveDiscoverTaskSchedule(@RequestBody DiscoverTaskSchedule discoverTaskSchedule){
        discoverTaskScheduleManager.save(discoverTaskSchedule);
        return discoverTaskSchedule;
    }

    // TODO: 2017/9/27 根据task id 查询出相关的调度任务


    @RequestMapping(value = "/taskid/{id}" , method = RequestMethod.GET)
    public DiscoverTaskSchedule findDiscoverTaskScheduleByTaskId(@PathVariable("id") String id){

        return discoverTaskScheduleManager.findDiscoverTaskScheduleByTaskId(id);

    }




    /**
    * 根据ID删除数据
    * @param id
    */
    @RequestMapping(value = "/{id}" , method = RequestMethod.DELETE)
    @JsonView(Object.class)
    public void deleteDiscoverTaskSchedule(@PathVariable("id") String id){
        discoverTaskScheduleManager.delete(id);
    }
}
